package com.wsj.message_server.controller;

import com.wsj.message_server.service.PushAppService;
import com.wsj.message_server.service.SystemIMService;
import com.wsj.message_server.utils.IMUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/system/im")
public class SystemIMController {

    @Autowired
    private SystemIMService service;

    /**
     * 创建登录签名
     *
     * @param account
     * @return
     */
    @GetMapping("v1/getIMLoginSign")
    public String getIMLoginSign(@RequestParam(value = "account") String account) {
        System.out.println("getIMLoginSign account：" + account);
        return IMUtils.createUserSign(account);
    }

    /**
     * 添加IM好友
     * @param From_Account
     * @param To_Account
     * @param Remark
     * @param GroupName
     * @param AddSource
     * @param AddWording
     * @param AddType
     * @return
     */
    @GetMapping("v1/addFriend")
    public String addFriend(@RequestParam(value = "From_Account") String From_Account,
                            @RequestParam(value = "To_Account") String To_Account,
                            @RequestParam(value = "Remark", defaultValue = "") String Remark,
                            @RequestParam(value = "GroupName", defaultValue = "") String GroupName,
                            @RequestParam(value = "AddSource",defaultValue="AddSource_Type_ios") String AddSource,
                            @RequestParam(value = "AddWording", defaultValue = "") String AddWording,
                            @RequestParam(value = "AddType", defaultValue = "Add_Type_Single") String AddType) {
        return service.addFriend(From_Account, To_Account, Remark, GroupName, AddSource, AddWording, AddType);
    }


    /**
     * 删除IM好友
     * @param From_Account
     * @param To_Account
     * @param DeleteType
     * @return
     */
    @GetMapping("v1/deleteFriend")
    public String deleteFriend(@RequestParam(value = "From_Account") String From_Account,
                      @RequestParam(value = "To_Account") String To_Account,
                      @RequestParam(value = "DeleteType", defaultValue = "Delete_Type_Single") String DeleteType) {

        return service.deleteFriend(From_Account, To_Account, DeleteType);
    }
    /**
     * 删除所有IM好友双向
     * @param From_Account
     * @param DeleteType
     * @return
     */
    @GetMapping("v1/deleteFriendAll")
    public String deleteFriendAll(@RequestParam(value = "From_Account") String From_Account,
                               @RequestParam(value = "DeleteType", defaultValue = "Delete_Type_Both") String DeleteType) {

        return service.deleteFriendAll(From_Account, DeleteType);
    }


    @GetMapping("v1/updateFriend")
    public String updateFriend(@RequestParam(value = "From_Account") String From_Account,
                         @RequestParam(value = "To_Account") String To_Account,
                         @RequestParam(value = "Tag", defaultValue = "Tag_SNS_IM_Remark") String Tag,
                         @RequestParam(value = "Value") Object Value) {

        return service.updateFriend(From_Account, To_Account, Tag, Value);
    }

    /**
     * 添加IM黑名单
     * @param From_Account
     * @param To_Account
     * @return
     */
    @GetMapping("v1/blackListAdd")
    public String blackListAdd(@RequestParam(value = "From_Account") String From_Account,
                         @RequestParam(value = "To_Account") String To_Account) {

        return service.blackListAdd(From_Account, To_Account);
    }

    /**
     * 删除IM黑名单
     * @param From_Account
     * @param To_Account
     * @return
     */
    @GetMapping("v1/blackListDelete")
    public String blackListDelete(@RequestParam(value = "From_Account") String From_Account,
                               @RequestParam(value = "To_Account") String To_Account) {

        return service.blackListDelete(From_Account, To_Account);
    }

    @Autowired
    private PushAppService service1;

    @GetMapping("v1/androidApp")
    public String androidApp(@RequestParam(value = "title") String title,
                             @RequestParam(value = "content") String content,
                             @RequestParam(value = "token") String token,
                             @RequestParam(value = "type")String type) {
        return service1.androidApp(title, content, token,type);
    }

    @GetMapping("v1/iosApp")
    public String iosApp(@RequestParam(value = "title") String title,
                         @RequestParam(value = "content") String content,
                         @RequestParam(value = "token") String token,
                         @RequestParam(value = "type")String type) {
        return service1.iosApp(title, content, token,type);
    }
}
